import instacne from "../request";
import type { Ref } from "vue";

/**
 * 查询所有一级分类及子分类  商品分类  /productCategory/list/withChildren
 */
// interface childrenItem {
//   description: string;
//   icon: string;
//   id: number;
//   keywords: string;
//   level: number;
//   name: string;
//   navStatus: number;
//   parentId: number;
//   productCount: number;
//   productUnit: string;
//   showStatus: number;
//   sort: number;
// }

const productCategory = () => {
    return instacne.get("/productCategory/list/withChildren");
};

/**
 *  分页查询推荐品牌 商品品牌  /brand/list
 */
interface IBrandListParams {
    brandName?: string | Ref<string>;
    pageNum?: number | Ref<number>;
    pageSize?: number | Ref<number>;
    recommendStatus?: number | Ref<number>;
}
interface IBrandListItem {
    brandId: number;
    brandName: string;
    id: number;
    recommendStatus: number;
    sort: number;
    attributeCount?: number;
    paramCount?: number;
    name?: string;
}
interface IBrandListRes {
    list: IBrandListItem[];
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
}
const brandList = (data: IBrandListParams): Promise<IBrandListRes> => {
    return instacne.get("/brand/list", { params: data });
};

/**
 *  属性类型  /productAttribute/category/list
 */
const attrCategory = (data: IBrandListParams): Promise<IBrandListRes> => {
    return instacne.get("/productAttribute/category/list", { params: data });
};

/**
 *  关联专题  /subject/listAll
 */
const subjectList = () => {
    return instacne.get("/subject/listAll");
};

/**
 *  关联优选  /prefrenceArea/listAll
 */
const preferList = () => {
    return instacne.get("/prefrenceArea/listAll");
};

/**
 *  提交添加商品
 */
const productCreate = (data: any) => {
    return instacne.post("/product/create", data);
};

export {
    productCategory,
    brandList,
    attrCategory,
    subjectList,
    preferList,
    productCreate,
};
export type { IBrandListParams, IBrandListItem, IBrandListRes };